package com.mvp.shq.washer.ui.order;

import com.mvp.shq.washer.entity.OrderInfo;
import com.mvp.shq.washer.entity.User;
import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.result.OrderResult;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.android.FragmentEvent;

import java.util.List;

/**
 * Created by Administrator on 2017/8/19.
 */

public class OrderPresenter extends OrderConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void getOrders(int pageNo,int pageSize) {
        User user = SpUtil.getUser();
        if (user == null){
            return;
        }
        String userId = user.getId();
        String token = SpUtil.getToken();
        model.getOrders(token,userId,pageNo,pageSize)
                .compose(getFragmentLifecycleProvider().bindToLifecycle())
                .subscribe(new BaseObserver<OrderResult>(view) {
                    @Override
                    protected void onSuccees(BaseResult<OrderResult> t) throws Exception {
                        if (t.isError()){
                            view.orderF(t.getMsg());
                        }else {
                            view.orderS(t.getData().getList());
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        e.printStackTrace();
                        view.orderF("未知错误");
                    }
                });
    }
}
